<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?=getValInArr(getSess(SESS_DIC),array('webInfo','webtitle'))?></title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script src="<?php echo base_url().'public/home/js/' ?>jquery.js"></script>
    <?php 
        include_once "public/home/html/alert.php" ;
     ?>
    <script type="text/javascript" src="<?php echo base_url().'public/home/js/' ?>function.js"></script>
    <?php include_once "public/home/html/broadcast.php"  ?>
    <link rel="stylesheet" href="<?php echo base_url().'public/home/css/' ?>index.css">
    <?php include_once "public/home/html/bootstrap.php"  ?>
    <style>
        .search-border{
            background: #eaeaea;
            border-radius: 20px;
            height: 50px;
            margin-top: 30px;
        }
        .search-border img{
            width: 20px;
            margin-left: 20px;
        }
        .search-border input{
            height: 44px;
            margin-top: 3px;
            margin-left: 15px;
            border: none;
            background: #eaeaea;
            width: 56%;
        }
        .search-list div{
            /*height: 40px;*/
            line-height: 40px;
            text-align: center;
            border-bottom: 1px solid #ececec;
        }
    </style>
</head>
<body>
    <input type="hidden" name="url" id="url"value="<?php echo base_url()?>">
    <input type="hidden" name="attend_id" id="attend_id" value="<?=$attend_id?>">
    <!-- <input type="hidden" name="teacher_code" id="teacher_code" value="<?php if(isset($teacher_code))echo $teacher_code;?>"> -->
    <input type="hidden" name="listen_time" id="listen_time" value="<?php if(isset($listen_time) && $listen_time)echo urldecode($listen_time);?>">
    <input type="hidden" name="course_units" id="course_units" value="<?php if(isset($course_units))echo urldecode($course_units);?>">
    <div class="search-border " oninput="getSearchList()">
        <img src="<?=base_url()?>public/home/images/search-icon.png">
        <input type="" name="" id="search" data-id="" placeholder="请输入课程名称">
        <button class="btn btn-primary" onClick="CheckSelf()">自定义</button>
    </div>
    <div class="search-list">
        
    </div>

    <script>
        $(function(){
            getSearchList() 
        })
        // 直接把当前input中的值当做课程
        function CheckSelf(){
            $.ajax({
                url: $("#url").val()+'Home/Search/setClass',
                type: 'POST',
                dataType: 'json',
                data: {
                    class_name: $("#search").val()
                },
                success:function(data){
                    var t=JSON.parse(data.v);
                    if(data.status){
                        // window.history.go(-1);
                        var href=getRootPath()+'/Home/Class_Assess/Index/'+$("#attend_id").val()+'?next=1';
                        location.href=href;
                    }
                }
            })  
        }
        $("body").keydown(function() {
            if (event.keyCode == "13") {//keyCode=13是回车键    
                // 回车直接把当前input中的值当做课程
                $.ajax({
                    url: $("#url").val()+'Home/Search/setClass',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        class_name: $("#search").val(),
                    },
                    success:function(data){
                        var t=JSON.parse(data.v);
                        if(data.status){
                            window.history.go(-1);
                        }
                    }
                })  
            }
         });
        // 获取搜索列表
        function getSearchList(){
            $.ajax({
                url: $("#url").val()+'Home/Search/getClassList',
                type: 'POST',
                dataType: 'json',
                data: {
                    class_name: $("#search").val(),                    
                    listen_time: $("#listen_time").val(),
                    course_units: $("#course_units").val(),
                },
                success:function(data){
                    var t=JSON.parse(data.v);
                    if(data.status){
                        var html='';                        
                        $.each(t, function(k, v) {
                             html+="<div onclick='getValue(this)' data-value='"+v['name']+"' data-id='"+v['id']+"'>【"+v['name']+"】"+v['username']+v['dept_name']+"</div>";
                        });
                        $(".search-list").html(html);
                    }
                }
            })            
        }
        
        // 点击搜索列表值，赋值到input上
        function getValue(obj){
           $.ajax({
                url: $("#url").val()+'Home/Search/setClass',
                type: 'POST',
                dataType: 'json',
                data: {
                    class_name: $(obj).attr('data-value')
                },
                success:function(data){
                    var t=JSON.parse(data.v);
                    if(data.status){
                        // window.history.go(-1);
                        var href=getRootPath()+'/Home/Class_Assess/Index/'+$("#attend_id").val()+'?next=1';
                        location.href=href;
                    }
                }
            })   
        }

    </script>

</body>
</html>
